package com.gpframework.module.common.domain.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.gpframework.common.annotation.Excel;
import com.gpframework.common.core.domain.entity.SysRole;
import com.gpframework.common.utils.DictUtils;
import com.gpframework.common.utils.StringUtils;
import com.gpframework.module.module.domain.vo.BrandStoreVo;
import com.gpframework.module.pay.utils.joinpay.sdk.utitls.StringUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.apache.commons.collections4.CollectionUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName CommonWxUserVo
 * @Author gpframework
 * @Date 2022-04-07
 * @Version 1.0.0
 * @Description 微信用户Vo对象
 */
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@Accessors(chain = true)
@JsonIgnoreProperties(value = {"handler"})
public class CommonWxUserVo implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @ApiModelProperty("主键")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long wxUserId;

    @ApiModelProperty("主键，和wxUserId一致")
    private Long userId;

    /**
     * 品牌id
     */
//    @Excel(name = "品牌id")
    @ApiModelProperty("品牌id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long brandId;

    /**
     * 会员类型：member、员工：employee
     */
//    @Excel(name = "会员类型")
    @ApiModelProperty("会员类型")
    private String wxType;

    /**
     * 员工类型
     */
    @ApiModelProperty("员工类型")
    private String employeesType;


    @ApiModelProperty("角色")
    private List<SysRole> sysRoles;

    /**
     * 品牌名称
     */
//    @Excel(name = "品牌名称")
    @ApiModelProperty("品牌名称")
    private String brandName;

    /**
     * 部门名称
     */
//    @Excel(name = "部门名称")
    @ApiModelProperty("部门名称")
    private String deptName;

    /**
     * 门店id
     */
//    @Excel(name = "门店id")
    @ApiModelProperty("门店id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long storeId;

    /**
     * 店铺id
     */
//    @Excel(name = "店铺id")
    @ApiModelProperty("店铺id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long lastStoreId;

    /**
     * 系统用户id
     */
//    @Excel(name = "系统用户id")
    @ApiModelProperty("系统用户id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long brandUserId;

    /**
     * uni-ubi人脸id
     */
    @ApiModelProperty("uni-ubi人脸id")
    private String guid;

    /**
     * 微信小程序openid
     */
//    @Excel(name = "微信小程序openid")
    @ApiModelProperty("微信小程序openid")
    private String wxAppletOpenid;

    /**
     * 微信公众号openid
     */
//    @Excel(name = "微信公众号openid")
    @ApiModelProperty("微信公众号openid")
    private String wxPublicOpenid;

    /**
     * 微信unionId
     */
//    @Excel(name = "微信unionId")
    @ApiModelProperty("微信unionId")
    private String unionId;

    /**
     * 微信号
     */
//    @Excel(name = "微信号")
    @ApiModelProperty("微信号")
    private String wechatCode;

    /**
     * 用户编号;员工工号
     */
//    @Excel(name = "用户编号;员工工号")
    @ApiModelProperty("用户编号;员工工号")
    private String userCode;

    /**
     * 昵称
     */
//    @Excel(name = "昵称")
    @ApiModelProperty("昵称")
    private String nickname;

    /**
     * 真实名称
     */
    @Excel(name = "用户名称", sort = 3)
    @ApiModelProperty("真实名称")
    private String userName;

    /**
     * 性别
     */
    @Excel(name = "性别", sort = 2, dictType = "gp_sex")
    @ApiModelProperty("性别")
    private String sex;

    /**
     * 头像url
     */
//    @Excel(name = "头像url")
    @ApiModelProperty("头像url")
    private String headImage;

    /**
     * 区域id
     */
//    @Excel(name = "区域id")
    @ApiModelProperty("区域id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long areaId;

    /**
     * 详细住址
     */
//    @Excel(name = "详细住址")
    @ApiModelProperty("详细住址")
    private String address;

    /**
     * 微信号
     */
//    @Excel(name = "微信号")
    @ApiModelProperty("微信号")
    private String wxCode;

    /**
     * 手机号
     */
    @Excel(name = "手机号", sort = 4)
    @ApiModelProperty("手机号")
    private String phone;

    @ApiModelProperty("脱敏手机号")
    private String desPhone;

    /**
     * 身份证号
     */
//    @Excel(name = "身份证号")
    @ApiModelProperty("身份证号")
    private String idNumber;
    /**
     * 证件类型 其它1001、身份证1002
     */
    @ApiModelProperty("证件类型 其它1001、身份证1002")
    private Integer certificateType;

    /**
     * 生日
     */
//    @Excel(name = "生日", width = 30, dateFormat = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("生日")
    private Date birthday;

    /**
     * 邮箱
     */
//    @Excel(name = "邮箱")
    @ApiModelProperty("邮箱")
    private String email;

    /**
     * 简介
     */
//    @Excel(name = "简介")
    @ApiModelProperty("简介")
    private String synopsis;

    /**
     * 公司区域id
     */
//    @Excel(name = "公司区域id")
    @ApiModelProperty("公司区域id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long companyAreaId;

    /**
     * 公司详细地址
     */
//    @Excel(name = "公司详细地址")
    @ApiModelProperty("公司详细地址")
    private String companyAddress;

    /**
     * 婚姻情况
     */
//    @Excel(name = "婚姻情况")
    @ApiModelProperty("婚姻情况")
    private String marriageCondition;

    /**
     * 子女情况
     */
//    @Excel(name = "子女情况")
    @ApiModelProperty("子女情况")
    private String childrenCondition;

    /**
     * 录入人id
     */
//    @Excel(name = "录入人id")
    @ApiModelProperty("录入人id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long inputUserId;

    /**
     * 录入人名称
     */
    @Excel(name = "录入人名称")
    @ApiModelProperty("录入人名称")
    private String inputUserName;

    /**
     * 分享人id
     */
    @ApiModelProperty("分享人id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long shareId;

    /**
     * 分享人名称
     */
    @ApiModelProperty("分享人名称")
    @Excel(name = "合作商", sort = 18)
    private String shareName;

    /**
     * 状态;有效、无效、冻结、删除
     */
//    @Excel(name = "状态;有效、无效、冻结、删除")
    @ApiModelProperty("状态;有效、无效、冻结、删除")
    @Excel(name = "用户状态", sort = 19, dictType = "employees_status")
    private String status;

    /**
     * 是否进小程序默认打开二维码
     */
    @ApiModelProperty("是否进小程序默认打开二维码")
    private String defaultOpenQrcode;

    /**
     * 人脸id
     */
    @ApiModelProperty("人脸id")
    private String faceGuid;

    /**
     * 旷视人脸id
     */
    private String faceSetid;

    /**
     * 人脸图片
     */
    @ApiModelProperty("人脸图片")
    private String faceImage;

    @ApiModelProperty("人脸上传设备状态码")
    private String deviceStatusCode;

    @ApiModelProperty("人脸上传设备状态码描述符")
    private String deviceStatusCodeDesc;

    /**
     * 排序
     */
//    @Excel(name = "排序")
    @ApiModelProperty("排序")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long sort;

    @ApiModelProperty("状态")
    private Integer delStatus;

    /**
     * 备注
     */
    @Excel(name = "备注")
    @ApiModelProperty("备注")
    private String remarks;

    /**
     * 创建者
     */
    @ApiModelProperty("创建者")
    @Excel(name = "录入人", sort = 15)
    private String createBy;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("创建时间")
    @Excel(name = "录入日期", sort = 16, width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /**
     * 更新者
     */
    @ApiModelProperty("更新者")
    private String updateBy;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("更新时间")
    private Date updateTime;

    /**
     * 微信code
     */
    @ApiModelProperty(value = "微信code")
    private String js_code;

    /**
     * 登录后token
     */
    @ApiModelProperty("登录后token")
    private String loginToken;

    /**
     * 会员类型; 1潜在会员、2正式会员 30过期会员
     */
    @ApiModelProperty("会员类型; 10潜在会员、20正式会员 30过期会员")
    private String memberType;


    @ApiModelProperty("关联的门店")
    private List<BrandStoreVo> storeVos;

    /**
     * 储值金额
     */
    @ApiModelProperty("储值金额")
    private BigDecimal storedMoney = BigDecimal.ZERO;

    /**
     * 现有积分
     */
    @ApiModelProperty("现有积分")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long integralExisting;

    /**
     * 定金
     */
//    @Excel(name = "定金")
    @ApiModelProperty("定金")
    private BigDecimal deposit;

    /**
     * 押金
     */
//    @Excel(name = "押金")
    @ApiModelProperty("押金")
    private BigDecimal handsel;

    /**
     * 累计积分
     */
//    @Excel(name = "累计积分")
    @ApiModelProperty("累计积分")
    private Long integralTotal;

    /**
     * 已使用积分
     */
//    @Excel(name = "已使用积分")
    @ApiModelProperty("已使用积分")
    private Long integralUsed;

    /**
     * 过期积分
     */
//    @Excel(name = "过期积分")
    @ApiModelProperty("过期积分")
    private Long integralOverdue;




    /**
     * 会员码
     */
    @ApiModelProperty("会员码")
    private String qrCode;


    /**
     * 课程总节数
     */
    private int courseTotalNum;
    /**
     * 课程核销数
     */
    private int courseVerificationNum = 0;

    @ApiModelProperty("课程剩余数量")
    private Integer remaining = 0;

    @ApiModelProperty("会籍保护剩余时间")
    private String potentialOverdue;
    @ApiModelProperty("跟进次数")
    @Excel(name = "跟进次数", sort = 13)
    private Integer followNum;
    @ApiModelProperty("会籍销售员名称")
    @Excel(name = "会籍", sort = 5)
    private String salesmanName;
    @ApiModelProperty("跟进人id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long salesmanId;
    @ApiModelProperty("会员卡号")
    private String cardCode;
    @ApiModelProperty("会员卡名")
    private String cardName;
    @ApiModelProperty("次卡有效使用次数")
    private String cardEffQuantity;
    @ApiModelProperty("剩余有效时间")
    private String cardEffTime;

    @ApiModelProperty("定金列表")
    private List<CommonLabelVo> userDetailList;
    @ApiModelProperty("来源")
    @Excel(name = "来源", sort = 14, dictType = "member_origin")
    private String origin;
    private String registration;
    @ApiModelProperty("保护天数")
    private Integer protectDay;
    @ApiModelProperty("下次联系时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "预计联系时间", sort = 10, dateFormat = "yyyy-MM-dd HH:mm:ss", width = 20)
    private Date nextContactTime;
    @ApiModelProperty("跟进状态")
    @Excel(name = "跟进状态", sort = 13, dictType = "member_follow_status")
    private String followStatus;
    @ApiModelProperty("业务员跟进状态")
    private String salesmanFollowStatus;
    @ApiModelProperty("最后跟进时间")
    @Excel(name = "最后一次跟进时间", sort = 6, dateFormat = "yyyy-MM-dd HH:mm:ss", width = 20)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date lastTime;
    @ApiModelProperty("最后跟进内容")
    @Excel(name = "跟进内容", sort = 7)
    private String lastCommunicateContent;
    @ApiModelProperty("最后跟进人")
    @Excel(name = "最后跟进会籍", sort = 12)
    private String lastSalesmanName;
    @ApiModelProperty("最后跟进人id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long lastSalesmanId;

    @ApiModelProperty("推荐人id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long referrerUserId;
    @ApiModelProperty("推荐人名称")
    private String referrerUserName;
    @ApiModelProperty("标签idList")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private List<Long> labelIdList;
    @ApiModelProperty("标签名称")
    private String[] labelName;
    @ApiModelProperty("标签名称")
    @Excel(name = "用户标签", sort = 17)
    private String labelNames;
    @ApiModelProperty("卡物理id")
    private String cardPhysicalId;
    @ApiModelProperty("打卡次数")
    private Integer clockNum;
    @ApiModelProperty("最后一次打卡时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date lastClockTime;
    @ApiModelProperty("未打卡次数")
    private Integer unClockDays;
    @ApiModelProperty("角色所属门店/品牌")
    private String roleStoreName;
    @ApiModelProperty("角色名")
    private String roleName;
    @ApiModelProperty("店铺名称")
    @Excel(name = "门店", sort = 1)
    private String storeName;
    @ApiModelProperty("入职状态")
    private String entryStatus;
    @ApiModelProperty("角色id")
    private Long brandRoleId;
    @ApiModelProperty("跟进id")
    private Long followId;
    @ApiModelProperty("剩余保护天数")
    @Excel(name = "剩余保护天数", sort = 9)
    private Integer remainingDay;
    @ApiModelProperty("年龄")
    private Integer age;
    @ApiModelProperty("入会时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date memberStartTime;
    @ApiModelProperty("截止时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date memberEndTime;
    @ApiModelProperty("会籍id")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long salesId;
    @ApiModelProperty("会籍名称")
//    @Excel(name = "会籍",sort = 5)
    private String salesName;
    @ApiModelProperty("手牌号")
    private String tagNo;
    @ApiModelProperty("临时柜子编号")
    private String cabinetCode;
    @ApiModelProperty("跟进教练")
    private String coachName;

    @ApiModelProperty("课程总数")
    private Integer total = 0;
    @ApiModelProperty("课程已消耗数")
    private Integer useNum = 0;
    @ApiModelProperty("未跟进天数")
    @Excel(name = "未跟进天数", sort = 11)
    private Long notFollowDay = 0L;
    /**
     * 标签列表
     */
    @ApiModelProperty("标签列表")
    private List<CommonLabelVo> labelVoList;


    @ApiModelProperty("资源数据")
    private List<CommonResourceVo> commonResourceVos;





    @ApiModelProperty("等级id")
    private Long levelSettingId;

    @ApiModelProperty(value = "消费金额")
    private BigDecimal totalPrice = new BigDecimal(0).setScale(2, BigDecimal.ROUND_HALF_UP);

    @ApiModelProperty(value = "排名")
    private Integer ranking = 0;

    @ApiModelProperty(value = "未读信息条数（业务消息）")
    private Integer unreadMsgNum = 0;

    @ApiModelProperty(value = "分享数量")
    private Integer shareNum = 0;



    @ApiModelProperty("查询日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date searchDate;

    @ApiModelProperty(value = "拉取人数")
    private Integer pullNum = 0;

    @ApiModelProperty(value = "潜客数量")
    private Integer potentialUserNum = 0;

    @ApiModelProperty(value = "会员数量")
    private Integer memberNum = 0;

    @ApiModelProperty(value = "访客登记次数")
    private Integer visitorsNum = 0;

    @ApiModelProperty("入职时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date entryDate;

    @ApiModelProperty("离职时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date dimissionDate;

    @ApiModelProperty("标签ID")
    private Long labelId;

    @ApiModelProperty("是否已有人脸头像")
    private String isFaceImage;
    @ApiModelProperty("是否已有人脸Id")
    private String isFaceSetid;
    @ApiModelProperty("是否查询所有")
    private String isAll;
    @ApiModelProperty("是否查询所有")
    private String isCourse;
    @ApiModelProperty("卡产品状态")
    private String cardStatus;

    @ApiModelProperty("上课时间")
    private String classTime;

    @ApiModelProperty("运动格言")
    private String motto;
    @ApiModelProperty("附件字符串")
    private String resources;
    @ApiModelProperty("未锻炼天数")
    private String notSignedInDay;

    public void updateProperties() {
        if (CollectionUtils.isNotEmpty(getSysRoles())) {
            String roleNames = getSysRoles().stream()
                    .filter(e -> e != null && StringUtils.isNotBlank(e.getRoleName()))
                    .map(e -> e.getRoleName())
                    .collect(Collectors.joining(DictUtils.SEPARATOR));
            setRoleName(roleNames);
        }

        if (CollectionUtils.isNotEmpty(getStoreVos())) {
            String storeNames = getStoreVos().stream()
                    .filter(e -> e != null && StringUtils.isNotBlank(e.getStoreName()))
                    .map(e -> e.getStoreName())
                    .collect(Collectors.joining(DictUtils.SEPARATOR));
            setStoreName(storeNames);
        }
    }

    public List<CommonLabelVo> getLabelVoList() {
        if (StringUtil.isNotEmpty(this.labelVoList)) {
            return this.labelVoList;
        }
        if (StringUtil.isNotEmpty(this.labelNames)) {
            String[] split = this.labelNames.split(",");
            if (StringUtil.isNotEmpty(split) && split.length > 0) {
                ArrayList<CommonLabelVo> labelVoList = new ArrayList<>();
                CommonLabelVo labelVo;
                for (String labelName : split) {
                    labelVo = new CommonLabelVo();
                    labelVo.setLabelName(labelName);
                    labelVoList.add(labelVo);
                }
                return labelVoList;
            }
        }
        return labelVoList;
    }
}
